<?php
/**
 * Created by PhpStorm.
 * User: USER
 * Date: 2017/4/18
 * Time: 17:00
 */

namespace JsonRpc\Services;

use JsonRpc\Models\BaseModel;
use JsonRpc\Models\SysUser;

class Login extends BaseModel
{

    //查询用户信息
    public function getUserInfo($params)
    {
        if (!empty($params)) {
            $res = SysUser::where('username',$params['username'])->get();
            if ($res[0]['password'] !== md5($params['password']))
            {
                return [];
            }else{
                return $res;
            }
        }

    }

    //添加用户信息
    public function addUserInfo($params)
    {
        if (!empty($params)) {
            $res = SysUser::insert($params);
            if (!empty($res)) {
                return $res;
            }else{
                return [];
            }
        }
    }

    //更新用户信息
    public function updateUserInfo($params)
    {
        if (!empty($params)) {
            $res = SysUser::where('id',$params['id'])->update([
                'username' => $params['username'],
                'password' => $params['password'],
                'sex' => $params['sex'],
                'realname' => $params['realname'],
                'phone' => $params['phone'],
                'mobile' => $params['mobile'],
                'email' => $params['email'],
                'qq' => $params['qq'],
                'fax' => $params['fax'],
                'photo' => $params['photo'],
                'remark' => $params['remark'],
                'updated_by' => $params['updated_by'],
            ]);
            if (!empty($res)) {
                return $res;
            }else{
                return [];
            }
        }
    }
}